<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
    <title>稻道工场 社区粮店</title>
    <link rel="stylesheet" href="/thinkphp/Public/home/css/reset.css" />
    <link rel="stylesheet" href="/thinkphp/Public/home/css/store.css" />
    <script type="text/javascript" src="/thinkphp/Public/home/js/zepto.min.js" ></script>
    <script src="/thinkphp/Public/home/js/swiper.min.js"></script>
    <script src="/thinkphp/Public/home/js/jquery.min.js"></script>
</head>

<body>
		<div class="layout">
			<!--header-->
			<div class="wrapper">
				<div class="header">
					<a class="s_preson" href="<?php echo U('Users/index');?>" target="_blank"> < </a>
					<div class="store">
						<span>配送地址</span>
					</div>
				</div>
			</div>
			
			<div class="main-address">
				<h3 class="main-address-title">选择收货地址</h3>
                <?php if(is_array($addressList)): $i = 0; $__LIST__ = $addressList;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><div class="main-address-con">

                        <?php if($vo[sign_build] == 1): ?><ul class="main-address-box main-address-cur">
                        <?php else: ?>
                            <ul class="main-address-box"><?php endif; ?>
                            <li><span>收  货  人：</span><i><?php echo ($vo["consignee"]); ?></i></li>
                            <li><span>联系电话：</span><i><?php echo ($vo["tel"]); ?></i></li>
                            <li><span>市/区：</span><i>北京 \ <?php echo ($vo["zoneName"]); ?></i></li>
                            <li><span>收货地址：</span><i><?php echo ($vo["address"]); ?></i></li>
                            <li>
                                <em><a href="<?php echo U('Users/updataAddress',array('id'=>$vo['id']));?>">【修改】</a></em>
                                <em><a href="<?php echo U('Users/del',array('id'=>$vo['id']));?>">【删除】</a></em>
                                <em class="setDef fr" data="<?php echo ($vo["id"]); ?>">【设为默认地址】</em></li>
                            <li class="modify-add"><div class="arrow-up"></div><b>√</b><div class="main-address-tip">默认地址</div></li>
                        </ul>
                    </div><?php endforeach; endif; else: echo "" ;endif; ?>
                <a class="mian-address-btn" style="background:#F76C03; color:#ffffff;" onclick="returnCart()">返回购物车</a>
				<a class="mian-address-btn" href="<?php echo U('Users/addAddress');?>">添加新地址</a>
			</div>
		
			<div class="footer">
				<p>©2015 北京食安城信息科技有限公司，并保留所有权利</p>
			</div>
		</div>

	<script>

        function returnCart()
        {
            $(".main-address-con").each(
                    function(){
                        var aa=$(this).children().attr("class");
                        if(aa=="main-address-box main-address-cur")
                        {
                            alert("already default address");
                            var url = "<?php echo U('Order/Cart');?>";
                            window.location.href=url;
                        }else{
                            alert("请选择默认地址");
                            return false;
                        }
                    }
            );
        }

		$('.setDef').on('click', function() {
			$('ul.main-address-box').each(function(i) {
				$('ul.main-address-box').eq(i).removeClass('main-address-cur');
			})
			$(this).parents('ul.main-address-box').addClass('main-address-cur');

            var id=$(this).attr("data");    // 获得此条地址信息的ID

            $.ajax({
                url:"<?php echo U('Users/signBuild');?>",
                type:"POST",
                data:{
                    id:id
                },
                dataType:"html",
                timeOut:"1000",
                error: function(){alert('Error loading PHP document');},
                success: function(result){
                    if(result=="true")
                    {
                        alert("默认地址设置成功!!!");
                    }else{
                        alert("默认地址设置失败!!!");
                    }
                }
            });
		})
	</script>   
	</body>
</html>


<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

</body>
</html>